using System.Collections.Generic;

namespace ZSW.Framework.UIElement
{
    public class ZSWF_SwitchButtonGroup : ZSWF_InitMonoBehaviour
    {
        public bool allowSwitchOff = false;
        private List<ZSWF_SwitchButton> m_buttons = new List<ZSWF_SwitchButton>();

        public void AddButton(ZSWF_SwitchButton button)
        {
            m_buttons.Add(button);
            button.OnValueChanged.AddListener(isOn =>
            {
                OnValueChange(button, isOn);
            });
        }

        public void OnValueChange(ZSWF_SwitchButton button, bool isOn)
        {
            if (isOn)
            {
                hideAll();
            }
            if (allowSwitchOff)
            {
                button.SwitchIsOnUnCall(isOn);
            }
            else
            {
                button.SwitchIsOnUnCall(allowSwitchOff);
            }
        }

        public void hideAll()
        {
            foreach (var button in m_buttons)
            {
                button.SwitchIsOnUnCall(false);
            }
        }
    }
}